﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace SkeletonNET.Crud.KeyCache
{
    /// <summary>
    /// An interface which is used to lookup property data which have the Key attribute attached to.
    /// All the lookups are cached when called for the first time.
    /// </summary>
    public interface IEntityKeyCache
    {
        /// <summary>
        /// Get the value of the Key property
        /// </summary>
        /// <param name="entity">The entity to find the property with the Key attribute on.</param>
        /// <returns>Value of the Key property.</returns>
        object GetKeyValue(object entity);
        /// <summary>
        /// Get a string representation of the key property.
        /// </summary>
        /// <param name="entity">The entity to work on.</param>
        /// <returns>Name of the key property</returns>
        string GetKeyName(Type entity);
        /// <summary>
        /// Get the key expression of an entity.
        /// </summary>
        /// <typeparam name="TEntity">The entity to work on.</typeparam>
        /// <param name="id">ID of the entity value to use in the compare expression.</param>
        /// <returns>Expression to use in queries</returns>
        Expression<Func<TEntity,bool>> GetExpression<TEntity>(object id);
    }
}
